import { Action } from "redux-actions";
import { all, call, put, takeEvery } from "redux-saga/effects";
import { getDoctorList, getHealthList } from "../../axios/Request";
import { setDoctorlist, setHispitalList } from "../action/Actions";
import { getDoctorlist, getHispitalList } from "../action/ActionsForSaga";

/**
 * 获取医院数据并且存入store
 */
function* getHispitalListSaga(action: Action<any>) {
  const response = yield call(getHealthList, action.payload);
  yield put(setHispitalList(response.data.content));
}
/**
 * 设定全局异步设置医院数据的action
 */
function* watchFetchHispitalList() {
  yield takeEvery(getHispitalList, getHispitalListSaga);
}
/**
 * 获取医生数据并且存入store
 */
function* getDoctorListSaga(action: Action<any>) {
  const response = yield call(getDoctorList, action.payload);
  yield put(setDoctorlist(response.data.content));
}
/**
 * 设定全局异步设置医生数据的action
 */
function* watchFetchDoctorList() {
  yield takeEvery(getDoctorlist, getDoctorListSaga);
}
/**
 * 将多个asgas合并，并导出
 */
export default function* sagas() {
  yield all([watchFetchHispitalList(), watchFetchDoctorList()]);
}
